
    <!--
 * @Author: BF-202204111659\Administrator qiutengda@dingtalk.com
 * @Date: 2022-06-16 16:46:40
 * @LastEditors: BF-202204111659\Administrator qiutengda@dingtalk.com
 * @LastEditTime: 2022-07-12 10:04:20
 * @FilePath: \visiotrip-group\uni-H5\src\packageExp\components\modal\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <view class="modal-container">
    <!-- 操作弹框 -->
    <uni-popup ref="popup" type="bottom" :mask-click="false" :is-mask-click="false">
      <view class="model-view">
        <view class="model-content">
          <view class="model-title model-action-1" @click="toSelectPhotoList"
          :data-spmCntSuffix="'. modelAction.toSelectPhotoList@'"
              :data-custom="1"
              :data-spm="{'pos': '选择旅拍相册'}"
            >选择旅拍相册</view
          >
          <view class="model-title model-action" @click="toSelectPhoto"
          :data-spmCntSuffix="'. modelAction.toSelectPhoto@'"
              :data-custom="1"
              :data-spm="{'pos': '选择手机相册'}"
            >选择手机相册</view
          >
        </view>
        <view class="model-bottom">
          <view class="model-title model-cancel" @click="cancel()"
          :data-spmCntSuffix="'. modelAction.cancel@'"
              :data-custom="1"
              :data-spm="{'pos': '取消'}">取消</view>
        </view>
      </view>
    </uni-popup>
  </view>
</template>
  
  <script>
  import {upload} from '@/request/upload.js'
  const { censorImage } = require('@/serve/api.js');
  export default {
    props: {
      photoNumber: {
        type: Number,
        default: 1
      },
      modelType: {
        type: String,
        default: "popup",
      },
      pageType: {
        type: String,
        default: "center",
      },
      type: {
        type: String,
        default: "center",
      },
      title: {
        type: String,
        default: "",
      },
      value: {
        type: Boolean,
        default: false,
      },
      activatedTxt:{
        type: String,
        default: "确认",
      },
      selectIndex: {
        type: Number,
      },

    },
    data: () => ({
      selectType: '',
      state: [{mediaTemplate: {clips:[]},
	poiList: []}]

    }),
    computed: {},
    methods: {
      cancel() {
        this.$emit("input", false);
      },
      toSelectPhotoList() {
        console.log("###checkedItem", this.checkedItem, this.selectIndex)
        if (!this.$isLogin()) {
          return;
        }
        const url = '/packageUserCenter/pages/aigc/photoShootingAlbum'
        this.$navTo(url, {
          pageType: this.pageType,
        }, 'navigateTo')
      },
      // 相册
      toSelectPhoto ()  {
        console.log(this.photoNumber,'55555')
        let that = this
        that.$emit("input", false);
        uni.chooseMedia({
          count: that.photoNumber,
          sizeType: ["compressed"],
          sourceType: ["album"],
          mediaType: ["image"],
          success: async (result) => {

            uni.showLoading({
                title: '加载中…',
                mask: true
            })

            let resArr = []
        
            try {
              await Promise.all(result.tempFiles.map(async (file,index) => {
              // 等待异步操作完成，返回执行结果
                    let res = await this.uploadPhoto(file, index)
                    resArr.push(res)
              }))
              this.$emit("selectPhoto", resArr);
              uni.hideLoading()
            } catch(err){
              uni.hideLoading()
            }
          },
        })
      },
      async uploadPhoto  ( file,index,  isCamera,video  ) {
        let res
        if(file.tempFilePath) {
          res = await upload(
            file,
            "https://vtrip-media-edit.oss-cn-shanghai.aliyuncs.com",
            isCamera
          )
          const resp = await censorImage(res)
            if (resp.data) {
              return res
            } else {
              uni.hideLoading()
              uni.showModal({
                title: "提示",
                content: `第${index + 1}张图片涉嫌违规，请重新上传`,
              })
              return ''
            }
         
        }
      },

    },
    watch: {
      value(val) {
        if (val) {
          this.$refs.popup.open();
        } else {
          this.$refs.popup.close();
        }
      },
    },
  
    // 组件周期函数--监听组件挂载完毕
    mounted() {},
    // 组件周期函数--监听组件数据更新之前
    beforeUpdate() {},
    // 组件周期函数--监听组件数据更新之后
    updated() {},
    // 组件周期函数--监听组件激活(显示)
    activated() {},
    // 组件周期函数--监听组件停用(隐藏)
    deactivated() {},
    // 组件周期函数--监听组件销毁之前
    beforeDestroy() {},
  };
  </script>
  
  <style lang="less" scoped>
.modal-container ::v-deep .model-view {
  width: 710rpx;
  height: 454rpx;
  border-radius: 30rpx;
  margin: 0 auto;
}

.model-content {
  width: 710rpx;
  height: 230rpx;
  background: #ffffff;
  border-radius: 30rpx;
  text-align: center;
  .model-title {
    height: 114rpx;
    line-height: 114rpx;
    font-size: 38rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #027aff;
  }
  .model-action-1 {
    border-bottom: 1px solid #dedede;
  }
}
.model-cancel {
  text-align: center;
  width: 100%;
  height: 114rpx;
  line-height: 114rpx;
  background: #ffffff;
  border-radius: 27rpx;
  margin-top: 20rpx;
  font-size: 38rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #027aff;
}
</style>